/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SistemaBackup;

import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.sql.*;


/**
 *
 * 
 */
public class CadastroUsuario extends javax.swing.JFrame {
    
     MysqlConnect objcon;
     
////
    /**
     * Creates new form CadastroUsuario
     */
    public CadastroUsuario() {
        initComponents();
        objcon = new MysqlConnect();
        
       
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
        private void initComponents() {

                jLabel1 = new javax.swing.JLabel();
                jSeparator1 = new javax.swing.JSeparator();
                jLabel2 = new javax.swing.JLabel();
                jLabel3 = new javax.swing.JLabel();
                tfUsername = new javax.swing.JTextField();
                jLabel4 = new javax.swing.JLabel();
                jLabel5 = new javax.swing.JLabel();
                jLabel6 = new javax.swing.JLabel();
                tfEmail = new javax.swing.JTextField();
                jButton1 = new javax.swing.JButton();
                jLabel7 = new javax.swing.JLabel();
                jLabel8 = new javax.swing.JLabel();
                jLabel9 = new javax.swing.JLabel();
                jLabel10 = new javax.swing.JLabel();
                jLabel11 = new javax.swing.JLabel();
                jLabel12 = new javax.swing.JLabel();
                jButton2 = new javax.swing.JButton();
                tfPassword = new javax.swing.JPasswordField();
                tfConfirmPassword = new javax.swing.JPasswordField();
                jLabel13 = new javax.swing.JLabel();
                tfNome = new javax.swing.JTextField();
                jLabel14 = new javax.swing.JLabel();
                jLabel15 = new javax.swing.JLabel();
                jLabel16 = new javax.swing.JLabel();

                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

                jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

                jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
                jLabel2.setText("Cadastro de Usuário do LBC");

                jLabel3.setText("Login");

                jLabel4.setText("Senha");

                jLabel5.setText("Confirmar Senha");

                jLabel6.setText("Email");

                jButton1.setText("Cancelar");
                jButton1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                jButton1ActionPerformed(evt);
                        }
                });

                jLabel7.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
                jLabel7.setText("*");

                jLabel8.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
                jLabel8.setText("*");

                jLabel9.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
                jLabel9.setText("*");

                jLabel10.setText("entre 3-10 letras ou números");

                jLabel11.setText("digite novamente a senha para confirmar");

                jLabel12.setText("entre 3-20 letras e numeros");

                jButton2.setText("Cadastrar");
                jButton2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                jButton2ActionPerformed(evt);
                        }
                });

                jLabel13.setText("Nome");

                tfNome.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                tfNomeActionPerformed(evt);
                        }
                });

                jLabel14.setText("*   Nome Completo");

                jLabel15.setText("*    Digite seu email");

                jLabel16.setText("* Ja é cadastrado! Clique em cancelar");

                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
                getContentPane().setLayout(layout);
                layout.setHorizontalGroup(
                        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                                .addContainerGap()
                                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 256, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(jLabel2)
                                        .add(layout.createSequentialGroup()
                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                                        .add(layout.createSequentialGroup()
                                                                .add(jButton2)
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(jButton1))
                                                        .add(layout.createSequentialGroup()
                                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                                                        .add(jLabel3)
                                                                        .add(jLabel4)
                                                                        .add(jLabel5)
                                                                        .add(jLabel6)
                                                                        .add(jLabel13))
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                                                        .add(tfUsername)
                                                                        .add(tfEmail, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                                                                        .add(tfPassword)
                                                                        .add(tfConfirmPassword)
                                                                        .add(tfNome))))
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                        .add(layout.createSequentialGroup()
                                                                .add(jLabel7)
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(jLabel10))
                                                        .add(layout.createSequentialGroup()
                                                                .add(jLabel8)
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(jLabel12))
                                                        .add(layout.createSequentialGroup()
                                                                .add(jLabel9)
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(jLabel11))
                                                        .add(jLabel14)
                                                        .add(jLabel15)
                                                        .add(jLabel16))))
                                .addContainerGap(41, Short.MAX_VALUE))
                );
                layout.setVerticalGroup(
                        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(layout.createSequentialGroup()
                                                .add(98, 98, 98)
                                                .add(jLabel1))
                                        .add(layout.createSequentialGroup()
                                                .add(47, 47, 47)
                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                        .add(layout.createSequentialGroup()
                                                                .add(21, 21, 21)
                                                                .add(jLabel2)
                                                                .add(10, 10, 10)
                                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                                                        .add(jLabel13)
                                                                        .add(tfNome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                                        .add(jLabel14))
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                                        .add(jLabel3)
                                                                        .add(tfUsername, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                                        .add(jLabel7)
                                                                        .add(jLabel10))
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                                        .add(jLabel4)
                                                                        .add(jLabel8)
                                                                        .add(jLabel12)
                                                                        .add(tfPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                                                .add(jLabel5)
                                                                                .add(jLabel9)
                                                                                .add(jLabel11))
                                                                        .add(org.jdesktop.layout.GroupLayout.TRAILING, tfConfirmPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                                        .add(tfEmail, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                                        .add(jLabel6)
                                                                        .add(jLabel15))
                                                                .add(30, 30, 30)
                                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                                                        .add(jButton1)
                                                                        .add(jButton2)
                                                                        .add(jLabel16)))
                                                        .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 366, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                                .addContainerGap(52, Short.MAX_VALUE))
                );

                pack();
        }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        new Login().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        try{
            objcon.conecta();
            objcon.statement=objcon.conexao.createStatement();
            String sqlinsert ="insert into Funcionario (Nome,Login,Senha,Email) values ('"+    
		    tfNome.getText()+"','"+
                    tfUsername.getText()+"','"+
                    tfConfirmPassword.getText()+"','"+
                    tfEmail.getText()+"')";
            //JOptionPane.showMessageDialog(null,"sql = "+sqlinsert);
            objcon.statement.executeUpdate(sqlinsert);
            JOptionPane.showMessageDialog(null, "Cadastro realizado com sucesso !");
            objcon.statement.close();
            
            this.dispose();
            new Login().setVisible(true);
            
                    
        }catch (SQLException erro){
            
        
            JOptionPane.showMessageDialog(null, "Erro ao tentar cadastrar usuario");
        }
            
    }//GEN-LAST:event_jButton2ActionPerformed

        private void tfNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfNomeActionPerformed
                // TODO add your handling code here:
        }//GEN-LAST:event_tfNomeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadastroUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadastroUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadastroUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastroUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new CadastroUsuario().setVisible(true);
            }
        });
    }
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel10;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel12;
        private javax.swing.JLabel jLabel13;
        private javax.swing.JLabel jLabel14;
        private javax.swing.JLabel jLabel15;
        private javax.swing.JLabel jLabel16;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JSeparator jSeparator1;
        private javax.swing.JPasswordField tfConfirmPassword;
        private javax.swing.JTextField tfEmail;
        private javax.swing.JTextField tfNome;
        private javax.swing.JPasswordField tfPassword;
        private javax.swing.JTextField tfUsername;
        // End of variables declaration//GEN-END:variables
}
